home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / dsp / 56000tar.z / 56000tar / 56000 / speech / adpcm.hlp < prev    next >
Text File  |  1991-11-26  |  15KB  |  324 lines

  1. ;**************************************************************************
  2. ;
  3. ;   ADPCM.HLP
  4. ;
  5. ; Help file for ADPCM.ASM - Version 1.0 - 1/31/89
  6. ;
  7. ; Updated 3/31/89 - Tested with real-time operation
  8. ;
  9. ;**************************************************************************
  10.  
  11.  
  12. This help file is preliminary documentation for the DSP56001 implementation
  13. of the CCITT 32 kbit/s ADPCM speech coding algorithm. Full documentation
  14. will be provided in a complete applications note to be published in the near
  15. future. A version of 32 kbit/s ADPCM that does not adhere to the CCITT
  16. standard will be discussed in the upcoming applications note. It should
  17. provide comparable quality to the standard version and should obtain
  18. significantly better real-time performance but will not pass the CCITT
  19. test vectors.
  20.  
  21.  
  22. General Information:
  23.  
  24. The program ADPCM.ASM implements the algorithm defined in CCITT
  25. Recommendation G.721: "32 kbit/s Adaptive Differential Pulse Code
  26. Modulation" dated August 1986. For complete understanding of the DSP56001
  27. code it is essential to refer to Recommendation G.721. The initial version
  28. of this program is suitable for software testing on a DSP56001 ADS. It
  29. passes all of the mu-law and A-law test sequences as defined in Appendix II
  30. of the above document.
  31.  
  32.  
  33. Usage Notes:
  34.  
  35. This version of the ADPCM algorithm simulates PCM/ADPCM I/O by the file
  36. I/O routines on the DSP56001 ADS board. This is the most convenient method
  37. for verifying the CCITT test vectors. Any file containing PCM speech/data
  38. in ASCII hex characters may be used as input to the encoder. The test
  39. files provided by the CCITT are suitable for this purpose, however the
  40. file I/O routines on the ADS require they be in a different form than
  41. that provided by the CCITT. Each byte of PCM data must be separated by
  42. a space or a return. The best format for the test files is one PCM byte
  43. of data per line. Also the algorithm assumes the 8 bits of PCM data be
  44. in the upper 8 bits of register A1, therefore 4 zeros must be appended
  45. to the PCM bytes in the input file (leading zeros are not needed).
  46.  
  47. The encoder writes the ADPCM output to an output file in a similar
  48. format. In this case all 24 bits of register A1 are output. The program
  49. puts the 4 bits of ADPCM data into the upper 4 bits of register A1
  50. and sets the other bits to 0. Therefore the output file has 1 hex
  51. character of data followed by 5 zeroes. This is the correct format for
  52. input to the encoder.
  53.  
  54. For example the CCITT test file VECTOR1.MU containing mu-law PCM data
  55. is distributed in the format:
  56.  
  57.   ffa719920f9118a34d2b9a138f119620beaf1c941090159e36369e159010941c
  58.   afbe2096118f139b2b4da318910f9219a7fd2799128f119823cdab1a930f9116
  59.   a03e2f9c149010951eb6b61e951090149c2f3ea016910f931babcd2398118f12
  60.   <etc.>
  61.  
  62. This file was converted to the following format for input to the
  63. encoder:
  64.  
  65.   ff0000
  66.   a70000
  67.   190000
  68.   920000
  69.   f0000
  70.   910000
  71.   180000
  72.   <etc.>
  73.  
  74. Similarly the CCITT test file VECTOR2.MU containing mu-law ADPCM
  75. data is distributed in the format:
  76.  
  77.   0f07080708050c02010c0509050b030d0e030a060a040c02010c0409050b040d
  78.   0e020a050a050b020f0c0409050a030d01020b0509040b020e0d03090409030c
  79.   01010c050a050b040e0e020a0509030b010f0d0409050b040d01020b0509040c
  80.   <etc.>
  81.  
  82. This file was converted to the following format for input to the
  83. decoder:
  84.  
  85.   f00000
  86.   700000
  87.   800000
  88.   700000
  89.   800000
  90.   500000
  91.   c00000
  92.   <etc.>
  93.  
  94. To run data files through the algorithm requires both a PCM input
  95. file and an ADPCM input file. As an example the following sequence
  96. of ADS commands illustrate how to run the test files VECTOR1.MU and
  97. VECTOR2.MU:
  98.  
  99.   load ADPCM               ;Downloads ADPCM.LOD to the ADS board
  100.   break p:$46f             ;Sets a breakpt at the end of the main loop
  101.   input #1 VECTOR1.MU      ;Assigns VECTOR1.MU as input to the encoder
  102.   input #2 VECTOR2.MU      ;Assigns VECTOR2.MU as input to the decoder
  103.   output #1 OUT1.MU        ;Assigns the encoder output to file OUT1.MU
  104.   output #2 OUT2.MU        ;Assigns the decoder output to file OUT2.MU
  105.   go #1 :16384             ;Runs the code through 16,384 occurances of
  106.                            ; the above breakpt (VECTOR1.MU and VECTOR2.MU
  107.                            ; each contain 16,384 test words)
  108.   <after breakpt is reached>
  109.   output off               ;Closes output files - There should be a
  110.                            ; message indicating 16,384 words were
  111.                            ; transferred to each file
  112.  
  113. Please note that the mu-law or A-law initialization files should be
  114. run before the actual test files in order to get the correct output
  115. (see Appendix II of Recommendation G.721 for details).
  116.   
  117.  
  118.  
  119. Performance specifications:
  120.  
  121. The program uses only internal X and Y memory so no external data memory
  122. is required. However, approximatly 1250 words of total program memory is
  123. required, so there should be at least 1K of full-speed (no wait state)
  124. external Program RAM in order to accomodate this. The code is designed to
  125. implement one full-duplex channel, both encode (transmit) and decode
  126. (receive), on one DSP56001. To achieve real-time performance a DSP56001
  127. running at 27 MHz is required. A version of this program has been run on
  128. a 27 MHz DSP56001 with real-time speech signals. The only modification
  129. to the test program was to provide real-time I/O. No changes to the
  130. algorithm implementation were required. 
  131.  
  132. Current worst-case calculations for execution time show that the encoder
  133. portion runs in real-time while the decoder portion is potentially slightly
  134. slower than real-time. The encode algorithm takes 810 instruction cycles
  135. (1 instruction cycle = 2 clock cycles) for the worst case delay while the
  136. decode algorithm takes 897 cycles (not including I/O). I/O at a rate
  137. of 8 kHz per sample gives 125 microseconds to do both an encode and
  138. a decode. This translates into 3333 clock cycles on a DSP56001 running at
  139. 27 MHz. This allows for 833 instruction cycles each to do the encode and
  140. the decode algorithms. The typical execution time for simulation data is
  141. less than the worst case maximums given above. In the test of real-time
  142. operation, the overall execution time for both the encoder and decoder
  143. was never observed to be greater than real-time. (Note: The real-time test
  144. INCLUDED the synchronization routines in the decoder)
  145.  
  146. The following shows the order of execution of the routines and the worst
  147. case processing time (in instruction cycles) for each routine (a routine
  148. defined as the code between commented sections even though some processing
  149. for that function may not be included in this code):
  150.  
  151.       Encoder                            Decoder
  152.  
  153. FMULT (x8)     341                 FMULT (x8)     341
  154. ACCUM           13                 ACCUM           13
  155. LIMA             4                 LIMA             4
  156. MIX             14                 MIX             14
  157. EXPAND          10                 RECONST         13
  158. SUBTA            3                 ADDA             3
  159. LOG             22                 ANTILOG         25
  160. SUBTB            3                 TRANS           34
  161. QUAN            36                 ADDB             8
  162. RECONST          7                 ADDC            19
  163. ADDA             3                 XOR
  164. ANTILOG         25                 UPB (x8)        76
  165. TRANS           34                 UPA2            27
  166. ADDB             8                 LIMC             6
  167. ADDC            19                 UPA1            12
  168. XOR                                LIMD             8
  169. UPB (x8)        76                 FLOATA          22
  170. UPA2            27                 FLOATB          27
  171. LIMC             6                 TONE             5
  172. UPA1            12                 TRIGB           13
  173. LIMD             8                 FUNCTF          14
  174. FLOATA          22                 FILTA            6
  175. FLOATB          27                 FILTB            5
  176. TONE             5                 SUBTC           11
  177. TRIGB           13                 FILTC            5
  178. FUNCTF          14                 TRIGA            3
  179. FILTA            6                 FUNCTW           7
  180. FILTB            5                 FILTD            5
  181. SUBTC           11                 LIMB             4
  182. FILTC            5                 FILTE            9
  183. TRIGA            3                 COMPRESS        33
  184. FUNCTW           7                 EXPAND          10
  185. FILTD            5                 SUBTA            3
  186. LIMB             4                 LOG             22
  187. FILTE            8                 SUBTB            3
  188. misc.            4                 SYNC            80
  189.                                    misc.            7
  190. -------------------                -------------------
  191. TOTAL          810  Icycles        TOTAL          897  Icycles
  192.  
  193.  
  194. Note: In the decoder the routines EXPAND, SUBTA, LOG, SUBTB, and SYNC
  195.       are not necessary for the ADPCM algorithm. They are included for
  196.       synchronization of multiple PCM/ADPCM/PCM conversions on a single
  197.       channel. If only one PCM/ADPCM/PCM conversion is used the deletion
  198.       of these routines should not affect the output speech quality.
  199.       The worst-case decoder execution time will be 779 instruction
  200.       cycles without these routines which will meet real-time constraints
  201.       at 27 MHz. Please note that these routines ARE neccesary to pass
  202.       the CCITT test files.
  203.  
  204.  
  205. Terminology used in the DSP56001 code:
  206.  
  207. Most arithmetic symbols adhere to those in the G.721 specification and are
  208. generally obvious with the possible exception of
  209.  
  210.     ** = power of  - i.e. 2**(-4) = 2 to the power of -4
  211.  
  212. The following symbols correspond to the variable types defined in the
  213. G.721 specification:
  214.  
  215.     SM = signed magnitude value
  216.     TC = two's complement value
  217.     FL = floating point value
  218.  
  219. A number preceding one of these symbols shows the number of total bits
  220. in a particular variable. The full binary representation of a variable,
  221. including the location of the radix point, is given in Table 3 of Recom-
  222. mendation G.721.
  223.  
  224. For additional information to aid in understanding the code, the contents
  225. of registers or memory locations at certain points are detailed bit for
  226. bit. The terminology used is shown below. 
  227.  
  228.     . = location of implied radix point
  229.     i = integer bit
  230.     f = fraction bit
  231.     s = sign bit
  232.     m = mantissa bit
  233.     e = exponent bit
  234.     1 = bit is always 1
  235.     0 = bit is always 0
  236.     X = bit value is unknown
  237.         but is not significant
  238.  
  239.     An exception is the PCM word where
  240.         p = sign bit
  241.         s = segment bit
  242.         q = quantization level bit
  243.  
  244. Example:
  245.  
  246. ;   Y = 0iii i.fff | ffff ff00 | 0000 0000  (13SM)
  247. Y_T         DS      1               ;Quantizer scale factor
  248.  
  249.     This shows of variable definition of the scale factor Y. It is
  250.     defined as a 13-bit signed magnitude number with 4 integer bits
  251.     and 9 fractional bits. The value stored in memory is always
  252.     stored in the 24-bit format shown above with the implied radix
  253.     point between bits 18 and 19.
  254.  
  255. Example:
  256.  
  257. ;   A1 = 01mm mmm0 | 0000 0000 | 0000 0000 (A2=A0=0)
  258. ;   B1 = 0000 0000 | 0000 0000 | 0000 eeee (B2=B0=0)
  259.  
  260.     At the point where these comments appear in the code the register
  261.     A1 always contains a 1 in bit 22, 5 other mantissa bits, and all
  262.     other bits set to 0. Register B1 always contains 4 exponent bits
  263.     in bits 0 through 3 with all other bits set to 0. Registers A0,A2,
  264.     B0, and B2 are always set to 0.
  265.  
  266.  
  267. Implementation notes:
  268.  
  269. This code is designed to be used as a stand-alone module. For users that
  270. wish to run the standard CCITT ADPCM algorithm there should be no need to
  271. modify the DSP56001 code that implements the standard (only the file I/O
  272. section needs to be modified). The comments in the code are provided for
  273. those who may wish to modify the algorithm itself for various reasons.
  274. As noted above it is essential to refer to Recommendation G.721 to under-
  275. stand the DSP56001 code. For those that may wish to modify the DSP56001
  276. code the following may make the code somewhat easier to understand.
  277.  
  278. The code for this algorithm is written to obtain optimal speed (due to real-
  279. time constraints). In almost all cases an attempt is made to implement a
  280. given function in the most efficient manner possible on the DSP56001. The
  281. primary goal is to make the worst case execution time as short as possible.
  282. The secondary goal is to conserve program/data memory. This goal of overall
  283. efficiency is the reason that most variables are NOT right justified as
  284. implied in the G.721 specification. Since the DSP56001 uses fractional-based
  285. arithmetic (i.e. left justified) keeping data as close to left justified as
  286. possible results in a more efficient implementation. It does however make
  287. the code more difficult to understand. Extra comments showing the contents
  288. of registers at various points in the code have been added to help clarify
  289. especially complex operations.
  290.  
  291. The primary goal of execution speed is why code that is the same for both
  292. the encoder and the decoder is not made into subroutines. It was found that
  293. there was too much overhead involved in calling these subroutines to allow
  294. for real-time full-duplex performance. Not having subroutines results in
  295. the code requiring more program memory, but allows the code to run much
  296. faster. Even if the encoder and decoder shared routines the program would
  297. still require external program memory so additional high-speed RAM would
  298. still be required.
  299.  
  300. Also in an effort to improve efficiency, the parallel nature of the DSP56001
  301. is taken advantage of whenever possible. This causes the code to "run together"
  302. in many cases, such as getting data for the next section of code before the
  303. current section has been completed. This does however make the execution time
  304. of a particular routine more difficult to define exactly. 
  305.  
  306. A more detailed explanation of the DSP56001 code will be provided in the
  307. upcoming applications note, however the comments in the actual code will
  308. still provide the best aid in understanding the code.
  309.  
  310. As noted above, a version of this program has been tested with real-time
  311. speech signals. The I/O section was modified to transmit and receive PCM
  312. data (64 kbits/s) to/from a CODEC connected to the SSI port of the DSP56001.
  313. For test purposes the received data from the CODEC was run through the
  314. encoder routine, sent directly to the decoder routine, and the decoded PCM
  315. data sent out to the same CODEC. The modification to talk to the CODEC was
  316. relatively simple and no modifications were made to the algorithm implementa-
  317. tion. The operation of the test set-up with sample speech signals was performed
  318. and the output quality was found to be comparable to standard PCM encoding/
  319. decoding. Exhaustive tests with many types of voice-band telephone signals
  320. have not been performed, but since the code passes all of the CCITT test
  321. vectors the user may have reasonable confidence in the performance of this
  322. code.
  323.  
  324.